# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=nvchecker
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.10
pkgrel=1
pkgdesc="New version checker for software releases (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'mingw32' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/lilydjwg/nvchecker"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-tomli"
         "${MINGW_PACKAGE_PREFIX}-python-structlog"
         "${MINGW_PACKAGE_PREFIX}-python-appdirs"
         "${MINGW_PACKAGE_PREFIX}-python-tornado"
         "${MINGW_PACKAGE_PREFIX}-python-pycurl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-docutils"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-pygments"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-asyncio"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-httpbin"
              "${MINGW_PACKAGE_PREFIX}-python-flaky"
              "${MINGW_PACKAGE_PREFIX}-python-lxml")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-lxml: for the htmlparser source"
            "${MINGW_PACKAGE_PREFIX}-python-packaging: for the pypi source"
            "${MINGW_PACKAGE_PREFIX}-python-gobject: for nvchecker-notify"
            "${MINGW_PACKAGE_PREFIX}-libnotify: for nvchecker-notify"
            "git: support for git repositories")
source=("https://github.com/lilydjwg/nvchecker/archive/v${pkgver}.tar.gz")
sha256sums=('aac524ca54b55d44fd48547093346610e4dfd48c93449820d990fd6dc750bb60')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  "${MINGW_PREFIX}"/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    "${MINGW_PREFIX}"/bin/python setup.py install --prefix="${MINGW_PREFIX}" \
      --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE -t "$pkgdir"${MINGW_PREFIX}/share/licenses/$_realname

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done

  for _f in ini2toml notify; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${pkgdir}${MINGW_PREFIX}/bin/nvchecker-${_f}"
  done

  # Docs
  install -Dm644 docs/usage.rst -t "$pkgdir"${MINGW_PREFIX}/share/doc/$_realname/
  install -Dm644 sample_config.toml -t "$pkgdir"${MINGW_PREFIX}/share/doc/$_realname/
}
